package com.glory.erp.invoice.goodstype.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.glory.erp.invoice.goodstype.bean.GoodsType;
import com.glory.erp.invoice.goodstype.bean.GoodsTypeQuery;
import com.glory.erp.invoice.goodstype.dao.GoodsTypeDao;
import com.glory.erp.auth.base.BaseDaoImpl;
import com.glory.erp.auth.base.BaseQueryModel;

public class GoodsTypeDaoImpl extends BaseDaoImpl<GoodsType> implements GoodsTypeDao{

	public void doQbc(DetachedCriteria dc,BaseQueryModel qm){
		GoodsTypeQuery gqm = (GoodsTypeQuery)qm;
		if(gqm.getSupplier()!=null&&gqm.getSupplier().getUuid()!=null&&gqm.getSupplier().getUuid()!=-1){
			dc.add(Restrictions.eq("supplier", gqm.getSupplier()));
		}
		if(gqm.getName()!=null&&gqm.getName().trim().length()>0){
			dc.add(Restrictions.eq("name", gqm.getName()));
		}
	}

	public List<GoodsType> findAllBySuppierUuid(Long uuid) {
		String hql = "from GoodsType where supplier.uuid = ?";
		return this.getHibernateTemplate().find(hql,uuid);
	}

	public List<GoodsType> findAllUnionBySupplier(Long uuid) {
		String hql = "select distinct gt from Goods g join g.goodsType gt where gt.supplier.uuid = ?";
		return this.getHibernateTemplate().find(hql,uuid);
	}
}